博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[React + GraphQL] Use useLazyQuery to manually execute a query with Apollo React Hooks
阅读量:4983 次
发布时间:2019-06-12

本文共 1171 字,大约阅读时间需要 3 分钟。

When using useQuery from Apollo React Hooks, the request will be sent automatically after the component has been mounted. This might not be the desired behaviour as we might want to send the request in response to user action (for instance, after a button click).

In this lesson we're going to learn how to use useLazyQuery hook to execute a query manually in order to fetch dog pictures.

 

import React, { Fragment, useState } from "react";import { gql } from "apollo-boost";import { useLazyQuery } from "@apollo/react-hooks";const GET_DOGGO = gql`  query Dog($breed: String!) {    dog(breed: $breed) {      id      displayImage    }  }`;const App = () => {  const [breed, setBreed] = useState("dingo");  const [getDog, { loading, data }] = useLazyQuery(GET_DOGGO);  if (loading) {    return 

Loading...

; } return (
{data && data.dog ? (
Cute Doggo ) : null}
setBreed(event.target.value)} placeholder="Choose breed" />
);};export default App;

 

转载于:https://www.cnblogs.com/Answer1215/p/11431567.html

你可能感兴趣的文章
批处理实现多线程执行命令列表文件
查看>>
跟牛牛老师学习python自动化的第六天
查看>>
利用Flume将本地文件数据中收集到HDFS
查看>>
html5的优缺点
查看>>
Vim 加 Gmail 变身 Vmail
查看>>
P1294 高手去散步
查看>>
一次谷歌面试趣事
查看>>
(5) Orchard 开发之 Localization and NullLocalizer
查看>>
分类算法(1)--KNN
查看>>
每日记载内容总结3
查看>>
ajax等待请求
查看>>
NTP协议详解
查看>>
Java学习之equals和hashcode的关系
查看>>
一页纸商业计划书 (Business Plan) 模板(转载)
查看>>
什么是html
查看>>
妙用python之编码转换
查看>>
hdu 4451 Dressing 衣服裤子鞋 简单容斥
查看>>
TTTTTTTTTTTT Gym 100818B Tree of Almost Clean Money 树连剖分+BIT 模板题
查看>>
linux一些基本常识(四)
查看>>
Docker架构
查看>>